differences between "d.clear()" and "d={}"

Posted by Tshepang on Stack Overflow See other posts from Stack Overflow or by Tshepang
Published on 2010-04-28T19:30:42Z Indexed on 2010/04/28 19:37 UTC
Read the original article Hit count: 267

Filed under:
|

On my machine, the execution speed between "d.clear()" and "d={}" is over 100ns so am curious why one would use one over the other.

import timeit

def timing():
    d = dict()

if __name__=='__main__':
    t = timeit.Timer('timing()', 'from __main__ import timing')
    print t.repeat()

© Stack Overflow or respective owner

Related posts about python

Related posts about timing